{% extends 'airshow/base.html' %}

{% block title %}添加{{ table|title }}数据 - 珠海航展数据管理系统{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header">
            <h2 class="card-title mb-0">添加{{ table|title }}数据</h2>
        </div>
        <div class="card-body">
            <form method="post" class="needs-validation" novalidate>
                {% csrf_token %}
                {% for column in columns %}
                <div class="mb-3">
                    <label for="{{ column }}" class="form-label">{{ column|title }}</label>
                    <input type="text" class="form-control" id="{{ column }}" name="{{ column }}" required>
                    <div class="invalid-feedback">
                        请输入{{ column|title }}
                    </div>
                </div>
                {% endfor %}
                <div class="text-end">
                    <a href="{% url 'airshow:direct_data' table=table %}" class="btn btn-secondary">
                        <i class="fas fa-times"></i> 取消
                    </a>
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-save"></i> 保存
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

{% block extra_js %}
<script>
// 表单验证
(function () {
    'use strict'
    var forms = document.querySelectorAll('.needs-validation')
    Array.prototype.slice.call(forms).forEach(function (form) {
        form.addEventListener('submit', function (event) {
            if (!form.checkValidity()) {
                event.preventDefault()
                event.stopPropagation()
            }
            form.classList.add('was-validated')
        }, false)
    })
})()
</script>
{% endblock %}
{% endblock %} 